package com.example.xinhuazidian.utils

import android.content.Context
import com.yechaoa.yutilskt.YUtils
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader

/**
 * Created by cwj on 2023-3-17.
 *
 * Description:Json文件加载解析工具类
 */
class JsonFileUtil {

    companion object {
        fun loadFile(context: Context, fileName: String): String {
            val stringBuilder = StringBuilder()
            try {
                val inputStream = context.resources.assets.open(fileName)
                val isr = InputStreamReader(inputStream)
                val reader = BufferedReader(isr)
                var jsonLine: String?
                while (reader.readLine().also { jsonLine = it } != null) {
                    stringBuilder.append(jsonLine)
                }
                reader.close()
                isr.close()
                inputStream.close()
                YUtils.hideLoading()
            } catch (e: IOException) {
                e.printStackTrace()
                YUtils.hideLoading()
            }
            return stringBuilder.toString()
        }
    }
}